import { AchievementBonusData } from "../data/AchievementBonusData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { AchievementBonusItem } from "./AchievementBonusItem";
import { Cache } from "../../../cache/Cache";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class AchievementBonusItemsView
    
    export  class AchievementBonusItemsView /* flash.display.Sprite */
    {
        

        public set data(arg1: AchievementBonusData)
        {
            this._data = arg1;
            this.updateView();
            return;
        }

        public updateView(): void
        {
            this._curX = 0;
            this.clearAll();
            this.addAchievements();
            this.addItems();
            this.addBGold();
            return;
        }

        /* internal  */clearAll(): void
        {
            while (this.numChildren > 0) 
            {
                this.removeChildAt(0);
            }
            return;
        }

        /* internal  */addAchievements(): void
        {
            if (this._data == null) 
            {
                return;
            }
            this._leftView = new Object /* flash.display.Sprite */();
            this.addChild(this._leftView);
            var loc1=new Object /* flash.display.Bitmap */();
            loc1.bitmapData = GlobalClass.getBitmapData(ImagesConst.AchievementChengjiudian);
            loc1.y = 28;
            loc1.x = 9;
            this._leftView.addChild(loc1);
            this._chengjiudianIcon = new Object /* flash.display.Bitmap */();
            this._chengjiudianIcon.bitmapData = GlobalClass.getBitmap(ImagesConst.StrengthenEnable).bitmapData;
            this._chengjiudianIcon.x = 14;
            this._chengjiudianIcon.y = 4;
            this._leftView.addChild(this._chengjiudianIcon);
            this._txtAchievement = ObjCreate.createGTextField("", 0, 11, 54, 26, this._leftView);
            var loc2=this._txtAchievement.defaultTextFormat;
            loc2.align = flash.text.TextFormatAlign.CENTER;
            loc2.color = 15452226;
            this._txtAchievement.defaultTextFormat = loc2;
            this._txtAchievement.text = this._data.achievement.toString();
            if (this._data.achievement <= 0) 
            {
                this._leftView.visible = false;
            }
            else 
            {
                this._leftView.visible = true;
            }
            return;
        }

        public setTxtChengjiuGray(): void
        {
            this._txtAchievement.filters = [FilterConst.colorFilter];
            this._chengjiudianIcon.bitmapData = GlobalClass.getBitmap(ImagesConst.StrengthenDisable).bitmapData;
            return;
        }

        public unSetTxtChengjiuGray(): void
        {
            this._txtAchievement.filters = [];
            this._chengjiudianIcon.bitmapData = GlobalClass.getBitmap(ImagesConst.StrengthenEnable).bitmapData;
            return;
        }

        /* internal  */addItems(): void
        {
            var loc3=0;
            var loc4=0;
            var loc5=null;
            if (this._data.items == null || this._data.items == "") 
            {
                return;
            }
            var loc1=this.parseOcuData(this._data.items);
            this._curX = 77;
            var loc2=0;
            while (loc2 < loc1.length / 2) 
            {
                loc3 = loc1[2 * loc2];
                loc4 = loc1[2 * loc2 + 1];
                (loc5 = new AchievementBonusItem(loc3, loc4)).isDragAble = false;
                loc5.isDropAble = false;
                loc5.x = this._curX;
                loc5.y = 7;
                this.addChild(loc5);
                this._curX = this._curX + (loc5.width + 11);
                ++loc2;
            }
            return;
        }

        /* internal  */parseOcuData(arg1: string): Array<any>
        {
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=0;
            var loc1=arg1.split("#");
            var loc2=[];
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                arg1 = loc1[loc3] as string;
                if (!(arg1 == null || arg1 == "")) 
                {
                    loc4 = arg1.split(",");
                    loc5 = int(loc4[0]);
                    loc6 = int(loc4[1]);
                    if (!(!((loc7 = int(loc4[2])) == 0) && !(loc7 == Cache.instance.role.roleInfo.career))) 
                    {
                        loc2.push(loc5);
                        loc2.push(loc6);
                    }
                }
                ++loc3;
            }
            return loc2;
        }

        /* internal  */addBGold(): void
        {
            if (this._data.bGold <= 0) 
            {
                return;
            }
            return;
        }

        /* internal */ /* var */_data: AchievementBonusData;

        /* internal */ /* var */_curX: int;

        /* internal */ /* var */_txtAchievement: GTextFiled;

        /* internal */ /* var */_chengjiudianIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_leftView: Object /* flash.display.Sprite */;
    }
